import http from "../utils/request"
import {PageRequestType, ResponseType, PageResponseType} from "../types/Response";
import {AxiosResponse} from "axios";

const apiPrefix:string = "/company";

export interface CompanyType {
    // id
    id?:string|null|undefined
    info:string
    // 创建时间
    create_at?:any|null|undefined
}

export interface CompanyPageSearchType extends PageRequestType, CompanyType {
    current: 1;
    size: 10;
}


export async function addCompany(data: CompanyType): Promise<AxiosResponse<ResponseType<null>>> {
    return await http.request({
        data: data,
        url: apiPrefix,
        method: 'post'
    })
}

export async function deleteCompanyById(id: string): Promise<AxiosResponse<ResponseType<null>>> {
    return await http.request({
        params: {
            id
        },
        url: apiPrefix+'/id',
        method: 'delete'
    })
}

export async function deleteCompanyByIds(ids: string[]): Promise<AxiosResponse<ResponseType<null>>> {
    return await http.request({
        params: {
            ids
        },
        url: apiPrefix+'/batch',
        method: 'delete'
    })
}


export async function searchCompanyById(id: string): Promise<AxiosResponse<ResponseType<CompanyType>>> {
    return await http.request({
        params: {
            id
        },
        url: apiPrefix+'/id',
        method: 'get'
    })
}

export async function searchCompany(params?: CompanyType): Promise<AxiosResponse<ResponseType<CompanyType>>> {
    return await http.request({
        params: params,
        url: apiPrefix+'/last',
        method: 'get'
    })
}

export async function searchCompanyByPage(params: CompanyPageSearchType): Promise<AxiosResponse<ResponseType<PageResponseType<CompanyType>>>> {
    return await http.request({
        params: params,
        url: apiPrefix+'/page',
        method: 'get'
    })
}


export async function updateCompanyById(data: CompanyType): Promise<AxiosResponse<ResponseType<null>>> {
    return await http.request({
        data: data,
        url: apiPrefix,
        method: 'put'
    })
}
